package mh.entity;

import java.util.ArrayList;

import mh.util.Pair;

/**
 * Represents any kind of interaction between two different entities.<br>
 * A <code>Damage</code> is something that's carried by a damaging <code>Entity</code> to a to-be-damaged one.<br>
 * Each entity is asked to calculate its own damage by giving a Damage object through the <code>damage(Damage d)</code>
 * method.
 * 
 * @author Gianmarco Laggia
 * @author Alberto D'Este
 * 
 */
public class Damage {
	private final ArrayList<Pair<DamageEffectEnum, Integer>>	effects;
	private int													index	= 0;

	public Damage() {
		this.effects = new ArrayList<Pair<DamageEffectEnum, Integer>>();
		this.index = 0;
	}

	public void addEffect(DamageEffectEnum ef, int amount) {
		Pair<DamageEffectEnum, Integer> pair = new Pair<DamageEffectEnum, Integer>(ef, amount);
		this.effects.add(pair);
	}

	public ArrayList<Pair<DamageEffectEnum, Integer>> getEffects() {
		return this.effects;
	}

	public Pair<DamageEffectEnum, Integer> getNext() {
		if (this.index < this.effects.size()) {
			return this.effects.get(this.index++);
		} else {
			return null;
		}
	}

	public boolean hasNext() {
		return this.index < this.effects.size();
	}

	// ====================================== //
	//             DAMAGE FACTORY             //
	// ====================================== //
	public static Damage createFireDamage(int damageAmount) {
		Damage d = new Damage();
		d.addEffect(DamageEffectEnum.BURN, damageAmount);
		return d;
	}

	public static Damage createWaterDamage(int damageAmount) {
		Damage d = new Damage();
		d.addEffect(DamageEffectEnum.WET, damageAmount);
		return d;
	}

	public static Damage createBlastDamage(int damageAmount) {
		Damage d = new Damage();
		d.addEffect(DamageEffectEnum.BLAST, damageAmount);
		d.addEffect(DamageEffectEnum.BURN, Math.round(damageAmount / 10f));
		return d;
	}

}
